import { atLeast, last, safeParseFloat } from '@/utils/kris_utils'
import dayjs from 'dayjs'

function formatter(fieldCfg, value, payload = {}) {
  // const sets = payload.sets[fieldCfg.mapTo]
  // console.log('payload --------->', payload)
  // if (!(sets instanceof Map)) return fieldCfg.fallback
  //
  // const mapValue = sets.get(value)
  //
  // if (!atLeast(mapValue, ['label'])) return fieldCfg.fallback
  //
  // return mapValue.label
}

const hasOwnProperty = (options, value) => {
  return Object.prototype.hasOwnProperty.call(options, value)
}

function dateFormatter(fieldCfg, value, payload = {}) {
  if (!value) return null
  return dayjs(value).format('YYYY-MM-DD')
}

function dateStrToDate(fieldCfg, value, payload = {}) {
  if (!value) return null
  return dayjs(value).toDate()
}

export const FieldType = {
  BUILT: 1,
  CUSTOM: 2
}

export const fieldConfigs = [
  {
    label: '姓名',
    field: 'name',
    disabled: false,
    formatter: null,
    serialize: null,
    deserialize: null,
    fallback: '',
    ofTable: 'user_details',
    mapTo: 'name'
  },
  {
    label: '性别',
    field: 'gender',
    disabled: false,
    formatter(fieldCfg, value) {
      const options = {
        0: {
          value: 0,
          label: '女'
        },
        1: {
          value: 1,
          label: '男'
        }
      }

      if (hasOwnProperty(options, value)) {
        return options[value].value
      }
      return fieldCfg.fallback
    },
    serialize: null,
    deserialize: null,
    fallback: null,
    ofTable: 'user_details',
    mapTo: 'gender'
  },
  {
    label: '手机号',
    field: 'phone',
    disabled: false,
    formatter: null,
    serialize: null,
    deserialize: null,
    fallback: '',
    ofTable: 'user_details',
    mapTo: 'phone'
  },
  {
    label: '一寸照',
    field: 'oneInchPhoto',
    disabled: false,
    formatter: null,
    serialize: null,
    deserialize: null,
    fallback: null,
    ofTable: 'user_details',
    mapTo: 'one_inch_photo'
  },
  {
    label: '邮箱',
    field: 'email',
    disabled: false,
    formatter: null,
    serialize: null,
    deserialize: null,
    fallback: '',
    ofTable: 'user_details',
    mapTo: 'email'
  },
  {
    label: '简历附件',
    field: 'resumeAttachment',
    disabled: false,
    formatter: null,
    serialize: null,
    deserialize: null,
    fallback: null,
    ofTable: 'user_details',
    mapTo: 'resume_attachment'
  },
  {
    label: '出生年月',
    field: 'birthday',
    disabled: false,
    formatter: null,
    fallback: null,
    serialize: dateFormatter,
    deserialize: dateStrToDate,
    ofTable: 'user_details',
    mapTo: 'birthday_at'
  },
  {
    label: '民族',
    disabled: false,
    field: 'nation',
    formatter(fieldCfg, value, valueType) {
      if (atLeast(valueType, ['nation', 'id'])) {
        return valueType.id
      }
      return fieldCfg.fallback
    },
    serialize: null,
    deserialize: null,
    fallback: null,
    ofTable: 'user_details',
    mapTo: 'nation_id'
  },
  {
    label: '身份证有效期',
    field: 'idPeriodOfValidity',
    disabled: false,
    formatter: null,
    fallback: null,
    serialize: dateFormatter,
    deserialize: dateStrToDate,
    ofTable: 'user_details',
    mapTo: 'identity_card_at'
  },
  {
    label: '身份证',
    disabled: false,
    field: 'idNo',
    formatter: null,
    serialize: null,
    deserialize: null,
    fallback: '',
    ofTable: 'user_details',
    mapTo: 'identity_card'
  },
  {
    label: '身份证正面(国徽面)',
    field: 'frontOfIDCard',
    disabled: false,
    formatter: null,
    serialize: null,
    deserialize: null,
    fallback: null,
    ofTable: 'user_details',
    mapTo: 'identity_card_front'
  },
  {
    label: '身份证反面(人像面)',
    field: 'backOfIDCard',
    disabled: false,
    formatter: null,
    serialize: null,
    deserialize: null,
    fallback: null,
    ofTable: 'user_details',
    mapTo: 'identity_card_reverse'
  },
  {
    label: '现住址',
    field: 'currentAddress',
    disabled: false,
    formatter: null,
    serialize: null,
    deserialize: null,
    fallback: '',
    ofTable: 'user_details',
    mapTo: 'present_address'
  },
  {
    label: '婚姻状态',
    field: 'marriageStatus',
    disabled: false,
    formatter(fieldCfg, value, valueType) {
      if (atLeast(valueType, ['name', 'id'])) {
        return valueType.id
      }
      return fieldCfg.fallback
    },
    serialize: null,
    deserialize: null,
    fallback: null,
    ofTable: 'user_details',
    mapTo: 'marital_id'
  },
  {
    label: '学历',
    field: 'educationLevel',
    disabled: false,
    formatter(fieldCfg, value, valueType) {
      if (atLeast(valueType, ['name', 'id'])) {
        return valueType.id
      }
      return fieldCfg.fallback
    },
    serialize: null,
    deserialize: null,
    fallback: null,
    ofTable: 'user_details',
    mapTo: 'education_id'
  },
  {
    label: '身高',
    field: 'height',
    disabled: false,
    formatter(fieldCfg, value) {
      return value ? parseFloat(value) : 0
    },
    serialize: null,
    deserialize: null,
    fallback: null,
    ofTable: 'user_details',
    mapTo: 'height'
  },
  {
    label: '体重',
    field: 'weight',
    disabled: false,
    formatter(fieldCfg, value) {
      return value ? parseFloat(value) : 0
    },
    serialize: null,
    deserialize: null,
    fallback: null,
    ofTable: 'user_details',
    mapTo: 'weight'
  },
  {
    label: '户口类型',
    field: 'registeredResidenceType',
    disabled: false,
    formatter(fieldCfg, value) {
      const options = {
        0: {
          value: 0,
          label: '城市'
        },
        1: {
          value: 1,
          label: '农村'
        }
      }

      if (hasOwnProperty(options, value)) {
        return options[value].value
      }
      return fieldCfg.fallback
    },
    serialize: null,
    deserialize: null,
    fallback: null,
    ofTable: 'user_details',
    mapTo: 'registered_residence'
  },
  {
    label: '学历性质',
    field: 'educationType',
    disabled: false,
    formatter(fieldCfg, value) {
      const options = {
        0: {
          value: 0,
          label: '自考'
        },
        1: {
          value: 1,
          label: '成人教育'
        },
        2: {
          value: 2,
          label: '统招'
        }
      }

      if (hasOwnProperty(options, value)) {
        return options[value].value
      }
      return fieldCfg.fallback
    },
    serialize: null,
    deserialize: null,
    fallback: null,
    ofTable: 'user_details',
    mapTo: 'education_nature'
  },
  {
    label: '学校',
    field: 'school',
    disabled: false,
    formatter(fieldCfg, value, valueType) {
      if (atLeast(valueType, ['school_name', 'id'])) {
        return { value: valueType.id, label: valueType.school_name }
      }
      return fieldCfg.fallback
    },
    serialize(fieldCfg, value) {
      if (atLeast(value, ['value'])) {
        return value['value']
      }
      return fieldCfg.fallback
    },
    deserialize: null,
    fallback: null,
    ofTable: 'user_details',
    mapTo: 'school_id'
  },
  {
    label: '毕业日期',
    field: 'graduationDate',
    disabled: false,
    formatter: null,
    fallback: null,
    serialize: dateFormatter,
    deserialize: dateStrToDate,
    ofTable: 'user_details',
    mapTo: 'graduation_at'
  },
  {
    label: '专业',
    field: 'major',
    disabled: false,
    formatter: null,
    serialize: null,
    deserialize: null,
    fallback: '',
    ofTable: 'user_details',
    mapTo: 'major'
  },
  {
    label: '特长',
    field: 'speciality',
    disabled: false,
    formatter: null,
    serialize: null,
    deserialize: null,
    fallback: '',
    ofTable: 'user_details',
    mapTo: 'speciality'
  },
  {
    label: '银行账户',
    field: 'bankAccountNumber',
    disabled: false,
    formatter: null,
    serialize: null,
    deserialize: null,
    fallback: '',
    ofTable: 'user_details',
    mapTo: 'bank_card'
  },
  {
    label: '开户行',
    disabled: false,
    field: 'bank',
    formatter(fieldCfg, value, valueType) {
      if (atLeast(valueType, ['bankName', 'id'])) {
        return { value: valueType.id, label: valueType.bankName }
      }
      return fieldCfg.fallback
    },
    serialize(fieldCfg, value) {
      if (atLeast(value, ['value'])) {
        return value['value']
      }
      return fieldCfg.fallback
    },
    deserialize: null,
    fallback: null,
    ofTable: 'user_details',
    mapTo: 'bank_id'
  },
  {
    label: '政治面貌',
    disabled: false,
    field: 'politicalStatus',
    formatter(fieldCfg, value, valueType) {
      if (atLeast(valueType, ['name', 'id'])) {
        return valueType.id
      }
      return fieldCfg.fallback
    },
    serialize: null,
    deserialize: null,
    fallback: null,
    ofTable: 'user_details',
    mapTo: 'politic_id'
  },
  {
    label: '社保号码',
    field: 'socialSecurityNumber',
    disabled: false,
    formatter: null,
    serialize: null,
    deserialize: null,
    fallback: '',
    ofTable: 'user_details',
    mapTo: 'social_insurance'
  },
  {
    label: '紧急联系人',
    field: 'emergencyContact',
    disabled: false,
    formatter(fieldCfg, value) {
      try {
        const data = JSON.parse(value)
        if (!atLeast(data, ['name', 'phone'])) {
          return {
            name: '',
            relationship: '',
            contact: ''
          }
        }

        // return `${data['name']} ${data['relation']} ${data['phone']}`
        return {
          name: data['name'],
          relationship: data['relation'],
          contact: data['phone']
        }
      } catch (e) {
        return ''
      }
    },
    serialize(fieldCfg, value) {
      return JSON.stringify({
        name: value?.name || '',
        relation: value?.relationship || '',
        phone: value?.contact || ''
      })
    },
    deserialize: null,
    fallback: null,
    ofTable: 'user_details',
    mapTo: 'emergency_contact'
  },
  {
    label: '户籍地',
    field: 'domicile',
    disabled: false,
    formatter(fieldCfg, value, valueType) {
      if (atLeast(valueType, ['domicile_array']) && Array.isArray(valueType.domicile_array)) {
        return valueType.domicile_array.map(item => ({ label: item.name, value: item.id }))
      }
      return fieldCfg.fallback.slice()
    },
    serialize(fieldCfg, value) {
      const address = last(value)
      if (address && atLeast(address, ['label', 'value'])) {
        return address.value
      }
      return null
    },
    deserialize: null,
    fallback: [],
    ofTable: 'user_details',
    mapTo: 'domicile_id'
  },
  {
    label: '家庭电话',
    field: 'homePhone',
    disabled: false,
    formatter: null,
    serialize: null,
    deserialize: null,
    fallback: '',
    ofTable: 'user_details',
    mapTo: 'family_phone'
  },
  {
    label: '电脑技能',
    field: 'computerSkills',
    disabled: false,
    formatter: null,
    serialize: null,
    deserialize: null,
    fallback: '',
    ofTable: 'user_details',
    mapTo: 'computer_power'
  },
  {
    label: '现居住地',
    field: 'currentAddress2',
    disabled: false,
    formatter: null,
    serialize: null,
    deserialize: null,
    fallback: '',
    ofTable: 'user_details',
    mapTo: 'present_residence'
  },
  {
    label: '证书列表',
    field: 'certificateList',
    disabled: false,
    component: null,
    serialize: null,
    deserialize: null,
    fallback: [],
    formatter(fieldCfg, value, fallback, payload) {
      if (!value) return fieldCfg.fallback.slice()
      try {
        const list = JSON.parse(value)
        if (!Array.isArray(list) || list.length <= 0) return fieldCfg.fallback.slice()
        return list.map(item => {
          const { name, expire_at, attachment } = item
          return {
            name,
            expireDate: dayjs(expire_at).toDate(),
            attachment: attachment
          }
        })
        // return JSON.parse(value)
      } catch (e) {
        console.log(e)
        return []
      }
    },
    ofTable: 'user_details',
    mapTo: 'certificate_list'
  },
  {
    label: '家庭成员',
    disabled: false,
    field: 'familyMembers',
    component: null,
    serialize: null,
    deserialize: null,
    fallback: [],
    formatter(fieldCfg, value, fallback, payload) {
      console.log('fieldCfg --------->', fieldCfg)
      if (!value) return fieldCfg.fallback.slice()
      try {
        const list = JSON.parse(value)
        if (!Array.isArray(list) || list.length <= 0) {
          console.log('1123--------->', fieldCfg['field'])
          return fieldCfg.fallback.slice()
        }
        return list.map(item => {
          const { member, relationship, age, work_unit, political_outlook, occupations, phone } = item
          return {
            name: member,
            relationship,
            age,
            workplace: work_unit,
            political: political_outlook,
            career: occupations,
            phone
          }
        })
        // const politicalOutlookMap = payload.sets['politic_id']

        //
        // if (!(politicalOutlookMap instanceof Map)) return data
        //
        // data.forEach((item) => {
        //   const politic = item['political_outlook']
        //   // item['political_outlook'] = politicalOutlookMap.get(politic_id)?.label
        //   item['political_outlook'] = politic?.label
        // })
        //
        // return data
      } catch (e) {
        console.log(e)
        return []
      }
    },
    ofTable: 'user_details',
    mapTo: 'family_situation'
  },
  {
    label: '工作经历',
    field: 'workExperience',
    disabled: false,
    component: null,
    serialize: null,
    deserialize: null,
    fallback: [],
    formatter(fieldCfg, value, fallback, payload) {
      if (!value) return fieldCfg.fallback.slice()
      try {
        const list = JSON.parse(value)
        if (!Array.isArray(list) || list.length <= 0) return fieldCfg.fallback.slice()
        return list.map(item => {
          const {
            companyName,
            beginDate,
            endDate,
            reason_leaving,
            department,
            position,
            company_telephone,
            salary,
            jobDescription
          } = item
          return {
            companyName,
            beginDate: dayjs(beginDate).toDate(),
            endDate: dayjs(endDate).toDate(),
            department,
            post: position,
            reasonForLeaving: reason_leaving,
            companyPhone: company_telephone,
            salary,
            scopeOfWork: jobDescription
          }
        })
      } catch (e) {
        return []
      }
    },
    ofTable: 'user_details',
    mapTo: 'work_experience'
  },
  {
    label: '教育经历',
    disabled: false,
    field: 'educationalExperience',
    component: null,
    serialize: null,
    deserialize: null,
    fallback: [],
    formatter(fieldCfg, value, fallback, payload) {
      if (!value) return fieldCfg.fallback.slice()
      try {
        const list = JSON.parse(value)
        if (!Array.isArray(list) || list.length <= 0) return fieldCfg.fallback.slice()
        return list.map(item => {
          const { schoolName, beginDate, endDate, major, certificate_number, certificate, schoolType } = item

          return {
            schoolName,
            schoolType,
            major,
            beginDate: dayjs(beginDate).toDate(),
            endDate: dayjs(endDate).toDate(),
            certificate,
            certificateNo: certificate_number
          }
        })
      } catch (e) {
        return []
      }
    },
    ofTable: 'user_details',
    mapTo: 'education_experience'
  },

  {
    label: '工号',
    disabled: false,
    field: 'employeeNumber',
    formatter: null,
    serialize: null,
    deserialize: null,
    fallback: '',
    ofTable: 'user_companys',
    mapTo: 'no'
  },
  {
    label: '职位',
    disabled: false,
    field: 'post',
    formatter(fieldCfg, value, valueType) {
      if (atLeast(valueType, ['name', 'id'])) {
        return { value: valueType.id, label: valueType.name }
      }
      return fieldCfg.fallback
    },
    serialize(fieldCfg, value) {
      if (atLeast(value, ['value'])) {
        return value['value']
      }
      return fieldCfg.fallback
    },
    deserialize: null,
    fallback: null,
    ofTable: 'user_companys',
    mapTo: 'position_id'
  },
  {
    label: '身份',
    disabled: false,
    field: 'employeeType',
    formatter(fieldCfg, value) {
      const options = {
        0: {
          value: 0,
          label: '正式员工'
        },
        1: {
          value: 1,
          label: '实习员工'
        },
        2: {
          value: 2,
          label: '试用员工'
        }
      }

      if (hasOwnProperty(options, value)) {
        return options[value].value
      }
      return fieldCfg.fallback
    },
    serialize: null,
    deserialize: null,
    fallback: null,
    ofTable: 'user_companys',
    mapTo: 'identity'
  },
  {
    field: 'entryDate',
    label: '入职日期',
    disabled: false,
    formatter: null,
    serialize: dateFormatter,
    deserialize: dateStrToDate,
    ofTable: 'user_companys',
    mapTo: 'entry_at'
  },
  {
    field: 'department',
    label: '部门',
    disabled: false,
    serialize: null,
    deserialize: null,
    fallback: null,
    formatter(fieldCfg, value, department) {
      return department?.id || fieldCfg.fallback
      // const find = (value, department, path = []) => {
      //   if (!Array.isArray(department)) return null
      //
      //   for (const index in department) {
      //     const item = department[index]
      //     if (item.value === value) return [...path, item]
      //
      //     if (Array.isArray(item.children) && item.children.length > 0) {
      //       const res = find(value, item.children, [...path, item])
      //       if (res !== null) return res
      //     }
      //   }
      //
      //   return null
      // }
      //
      // const path = find(value, department)
      // if (!Array.isArray(path) || path.length <= 0) return ''
      //
      // return path.map((item) => item.label).join(' / ')
    },
    ofTable: 'user_companys',
    mapTo: 'department_id'
  },
  {
    field: 'status',
    label: '在职状态',
    disabled: false,
    formatter(fieldCfg, value) {
      const options = {
        0: {
          value: 0,
          label: '离职'
        },
        1: {
          value: 1,
          label: '在职'
        }
      }

      if (hasOwnProperty(options, value)) {
        return options[value].value
      }
      return fieldCfg.fallback
    },
    serialize: null,
    deserialize: null,
    fallback: null,
    ofTable: 'user_companys',
    mapTo: 'job_status'
  },
  {
    field: 'practiceBeginDate',
    label: '实习/试用开始日期',
    disabled: false,
    formatter: null,
    fallback: null,
    serialize: dateFormatter,
    deserialize: dateStrToDate,
    ofTable: 'user_companys',
    mapTo: 'practice_start_at'
  },
  {
    field: 'practiceEndDate',
    label: '实习/试用结束日期',
    disabled: false,
    formatter: null,
    fallback: null,
    serialize: dateFormatter,
    deserialize: dateStrToDate,
    ofTable: 'user_companys',
    mapTo: 'practice_end_at'
  },
  {
    field: 'dateOfbecomeARegularWorker',
    label: '转正日期',
    disabled: false,
    formatter: null,
    fallback: null,
    serialize: dateFormatter,
    deserialize: dateStrToDate,
    ofTable: 'user_companys',
    mapTo: 'regular_at'
  },
  {
    label: '部门领导',
    field: 'leader',
    disabled: false,
    formatter(fieldCfg, value, valueType) {
      if (!valueType) return fieldCfg.fallback
      return {
        value: valueType?.id,
        label: valueType?.username,
        data: valueType
      }
    },
    component: null,
    serialize(fieldCfg, value) {
      if (atLeast(value, ['value'])) {
        return value['value']
      }
      return fieldCfg.fallback
    },
    deserialize: null,
    fallback: null,
    ofTable: 'user_companys',
    mapTo: 'leader_id'
  },
  {
    label: '实习/试用薪资',
    disabled: false,
    field: 'salaryOfPractice',
    formatter(fieldCfg, value) {
      return value ? parseFloat(value) : 0
    },
    serialize: null,
    deserialize: null,
    fallback: null,
    ofTable: 'user_companys',
    mapTo: 'practice_salary'
  },
  {
    label: '转正薪资',
    field: 'regularSalary',
    disabled: false,
    formatter(fieldCfg, value) {
      return value ? parseFloat(value) : 0
    },
    serialize: null,
    deserialize: null,
    fallback: null,
    ofTable: 'user_companys',
    mapTo: 'regular_salary'
  },
  {
    label: '薪资',
    disabled: false,
    field: 'salary',
    formatter(fieldCfg, value) {
      return value ? parseFloat(value) : 0
    },
    serialize: null,
    deserialize: null,
    fallback: null,
    ofTable: 'user_companys',
    mapTo: 'current_salary'
  },
  {
    label: '劳动合同',
    field: 'laborContract',
    disabled: false,
    formatter: null,
    serialize: null,
    deserialize: null,
    fallback: null,
    ofTable: 'user_companys',
    mapTo: 'labor_contract'
  },
  {
    label: '劳动合同开始日期',
    disabled: false,
    field: 'laborContractBeginDate',
    formatter: null,
    fallback: null,
    serialize: dateFormatter,
    deserialize: dateStrToDate,
    ofTable: 'user_companys',
    mapTo: 'labor_contract_start'
  },
  {
    label: '劳动合同截至日期',
    disabled: false,
    field: 'laborContractEndDate',
    formatter: null,
    fallback: null,
    serialize: dateFormatter,
    deserialize: dateStrToDate,
    ofTable: 'user_companys',
    mapTo: 'labor_contract_end'
  },
  {
    label: '离职日期',
    disabled: false,
    field: 'departDate',
    formatter: null,
    fallback: null,
    serialize: dateFormatter,
    deserialize: dateStrToDate,
    ofTable: 'user_companys',
    mapTo: 'quit_at'
  },
  {
    label: '入职方式',
    disabled: false,
    field: 'entryMethod',
    formatter: null,
    serialize: null,
    deserialize: null,
    fallback: '',
    ofTable: 'user_companys',
    mapTo: 'entry_mode'
  },
  {
    label: '离职原因',
    disabled: false,
    field: 'reasonForLeaving',
    formatter: null,
    serialize: null,
    deserialize: null,
    fallback: '',
    ofTable: 'user_companys',
    mapTo: 'quit_reason'
  },
  {
    label: '入职次数',
    disabled: false,
    field: 'entryCount',
    formatter(fieldCfg, value, valueType) {
      if (!value) return fieldCfg.fallback
      const reg = new RegExp('^[0-9]*$')
      if (!reg.test(value)) return fieldCfg.fallback
      return value / 1
    },
    serialize: null,
    deserialize: null,
    fallback: 0,
    ofTable: 'user_companys',
    mapTo: 'entry_number'
  },
  {
    label: '宿舍',
    field: 'apartment',
    disabled: false,
    serialize(fieldCfg, value) {
      if (atLeast(value, ['value'])) {
        return value['value']
      }
      return fieldCfg.fallback
    },
    deserialize: null,
    fallback: null,
    formatter(fieldCfg, value, valueType) {
      if (!valueType) return fieldCfg.fallback
      return {
        value: valueType?.id,
        label: valueType?.name,
        data: valueType
      }
    },
    ofTable: 'user_companys',
    mapTo: 'room_id'
  },
  {
    label: '体检记录',
    field: 'physicalExamRecord',
    disabled: false,
    formatter: null,
    serialize: null,
    deserialize: null,
    fallback: null,
    ofTable: 'user_companys',
    mapTo: 'physical_examination'
  },
  {
    label: '离职薪资状态',
    disabled: false,
    field: 'departSalaryStatus',
    formatter,
    serialize: null,
    deserialize: null,
    fallback: null,
    ofTable: 'user_companys',
    mapTo: 'quit_salary_status'
  },
  {
    label: '临时电子居住证',
    disabled: false,
    formatter: null,
    field: 'temporaryResidencePermit',
    serialize: null,
    deserialize: null,
    fallback: null,
    ofTable: 'user_companys',
    mapTo: 'temporary_residence_permit'
  },
  {
    label: '介绍人',
    disabled: false,
    formatter(fieldCfg, value, valueType) {
      if (atLeast(valueType, ['id'])) {
        return valueType.id
      }
      return fieldCfg.fallback
    },
    field: 'introducer',
    serialize: null,
    deserialize: null,
    fallback: null,
    ofTable: 'user_companys',
    mapTo: 'introducer_id'
  },
  {
    label: '角色',
    disabled: false,
    formatter: (fieldCfg, value, valueType) => {
      if (!value) return fieldCfg.fallback.slice()
      try {
        const list = JSON.parse(value)
        if (!Array.isArray(list) || list.length <= 0) return fieldCfg.fallback
        return list
      } catch (error) {
        return fieldCfg.fallback.slice()
      }
    },
    field: 'roles',
    serialize: (fieldCfg, result) => {
      if (!Array.isArray(result) || result.length <= 0) return JSON.stringify(fieldCfg.fallback)
      return JSON.stringify(result)
    },
    deserialize: null,
    fallback: [],
    ofTable: 'user_companys',
    mapTo: 'roles'
  },
  {
    label: '职位头衔',
    disabled: false,
    formatter: (fieldCfg, value, valueType) => {
      if (!value) return fieldCfg.fallback.slice()
      try {
        const list = JSON.parse(value)
        if (!Array.isArray(list) || list.length <= 0) return fieldCfg.fallback
        return list
      } catch (error) {
        return fieldCfg.fallback.slice()
      }
    },
    field: 'title',
    ofTable: 'user_details',
    serialize: (fieldCfg, result) => {
      if (!Array.isArray(result) || result.length <= 0) return JSON.stringify(fieldCfg.fallback)
      return JSON.stringify(result)
    },
    deserialize: null,
    fallback: [],
    mapTo: 'title'
  },
  {
    label: '微信号',
    disabled: false,
    formatter: null,
    field: 'wx_number',
    ofTable: 'user_details',
    serialize: null,
    deserialize: null,
    fallback: null,
    mapTo: 'wx_number'
  },
  {
    label: '传真',
    disabled: false,
    formatter: null,
    field: 'fax',
    ofTable: 'user_details',
    serialize: null,
    deserialize: null,
    fallback: null,
    mapTo: 'fax'
  },
  {
    label: '名片',
    disabled: false,
    formatter: null,
    field: 'bus_card',
    ofTable: 'user_details',
    serialize: null,
    deserialize: null,
    fallback: null,
    mapTo: 'bus_card'
  },
  {
    label: '电子名片头像',
    disabled: false,
    formatter: null,
    field: 'picture',
    ofTable: 'user_details',
    serialize: null,
    deserialize: null,
    fallback: null,
    mapTo: 'picture'
  },
  {
    label: '电子名片头像（水印版）',
    disabled: false,
    formatter: null,
    field: 'picture_watermark',
    ofTable: 'user_details',
    serialize: null,
    deserialize: null,
    fallback: null,
    mapTo: 'picture_watermark'
  }
]
